package MineGod;

import java.awt.Font;
import java.io.IOException;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;
import org.newdawn.slick.TrueTypeFont;


public class GUILabelInventory extends GUILabel{

	public static Texture gunPowder;
	public static Texture diamond;
	private double labelWidth = 16;
	public static TrueTypeFont gpFont;
	public static TrueTypeFont dFont;
	
	
	public GUILabelInventory(){
		x = 257;
		y = Chunk.CHUNK_PIXEL_HEIGHT;
		width = 64;
		height = 64;
		active = true;
		hidden = false;
	}
	
	public static void loadTexture(){
		try {
			gunPowder = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/gunpowder.png"));
			diamond = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/diamond.png"));
			Font awtFont = new Font("Times New Roman", Font.BOLD, 24);
			gpFont = new TrueTypeFont(awtFont, true);
			dFont = new TrueTypeFont(awtFont, true);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	@Override
	public Texture getTexture() {
		return null;
	}
	
	public void render(double zIndex){
		if (!hidden){
			GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
			GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
			boolean enoughG = MineGod.player.inventory[0] > 0;
			renderItem(gunPowder, enoughG, x, y, zIndex);
			gpFont.drawString((float)x + 20, (float)y, MineGod.player.inventory[0]+"");
			boolean enoughD = MineGod.player.inventory[1] > 0;
			renderItem(diamond, enoughD, x, y+labelWidth*2, zIndex);
			dFont.drawString((float)x + 20, (float)(y+labelWidth*2), MineGod.player.inventory[1]+"");
			
		}
	}
		
	
	private void renderItem(Texture tex, boolean enough, double newx, double newy, double zIndex){
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
		tex.bind();
		if (enough){
			GL11.glColor3d(1, 1, 1);
		} else{
			GL11.glColor3d(.25, .25, .25);
		}
		GL11.glBegin(GL11.GL_QUADS);
			GL11.glNormal3d(0, 0, 1);
			GL11.glTexCoord2d(0.0, 0.0);
			GL11.glVertex3d(newx, newy, zIndex);
			GL11.glTexCoord2d(1.0, 0.0);
			GL11.glVertex3d(newx + labelWidth, newy, zIndex);
			GL11.glTexCoord2d(1.0, 1.0);
			GL11.glVertex3d(newx + labelWidth, newy + labelWidth, zIndex);
			GL11.glTexCoord2d(0.0, 1.0);
			GL11.glVertex3d(newx, newy + labelWidth, zIndex);
		GL11.glEnd();
	}
	
	

}
